/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh 
 												
Class							:				StatusCondition
 
Function						: 				Provides a class for holding a status 
												condition 
****************************************************************************/

package planninglanguage.conditions;

import org.jdom.Element;

import util.XMLWriter;
import base.WargusGameState;
import base.WargusStateImporter;
import base.WargusUnit;

public class StatusCondition extends Condition {
	int m_unitID;
	String m_status;
	
	public StatusCondition(int a_unitID,String a_status)
	{
		m_unitID = a_unitID;
		m_status = a_status;
	}
	public String toString(int tabs)
	{
		String n = super.toString(tabs);
		n = n + "Unit Id is: " + m_unitID;
		n = n + "Status is: " + m_status;
		return n;
	}
	public String getStatus()
	{
		return m_status;		
	}
	public void setStatus(String status)
	{
		m_status = status;
	}
	public boolean compare(StatusCondition c)
	{
		if(m_status.equals(c.m_status) && m_unitID==c.m_unitID)
			return true;
		else
			return false;
	}
	public boolean test(WargusGameState a_gameState)
	{		
//		System.out.println("StatusCondition: test( unitID = " + m_unitID + " status = " + m_status + ")");
		
		WargusUnit u = a_gameState.getUnit(m_unitID);
		
		if (u != null) {
			if (WargusStateImporter.statusToString(u.getStatus()[0]).equals(m_status))
				return true;
		}
		return false;
	}
	
	public void writeXML(XMLWriter w) {
		w.tag("condition type=\""+this.getClass().getSimpleName()+"\"");
		{
			w.tag("unit-id", m_unitID);
			w.tag("status", m_status);
		}
		w.tag("/condition");
	}
	
	protected static Condition loadConditionFromXML(Element e) {
		return new StatusCondition(Integer.parseInt(e.getChildText("unit-id")),
				e.getChildText("status"));
	}
}
